home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 1
/
Amiga Tools.iso
/
egs-tools
/
egs_demo-version
/
egs_devels
/
examples
/
beginner_gadgets
/
gadget5.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-06
|
7KB
|
185 lines
/**************************************************************************
***** Gadget Demo 5 *****
***** *****
***** by John J. Karcher *****
***** *****
***** 10 August 1992 *****
***** 10 Jan 1993 mvk *****
***** *****
**************************************************************************/
/*
This program opens up a window with a three-by-three array of
gadgets, using egsgadbox.library. To make it a little more
interesting, the gadgets are grouped into three groups of
equivalent gadgets each. Try it; you'll see.
This demonstrates how to use CreateHorizBox() and
CreateVertiBox() together to make gadget arrays. It also
shows that gadget IDs can be used to your advantage.
*/
#include <stdio.h>
#include <exec/types.h>
#include <egs/egsintui.h>
#include <egs/egsgadbox.h>
#include <proto/exec.h>
#include <egs/proto/all.h>
#define GAD_1_ID 1
#define GAD_2_ID 2
#define GAD_3_ID 3
BYTE CreateWindow(void);
BYTE CreateGfx(void);
struct Library *EGSIntuiBase;
struct Library *EGBBase;
struct EB_GadContextNode *GadCon;
struct EI_Window *Win;
BYTE CreateGfx(void)
{
EB_GadBoxPtr root, b1, b2, b3;
BYTE ret = 0;
if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
{
root = EB_CreateVertiBox(GadCon);
EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
b1 = EB_CreateHorizBox(GadCon);
EB_AddLastSon(root, b1);
EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
b2 = EB_CreateHorizBox(GadCon);
EB_AddLastSon(root, b2);
EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
b3 = EB_CreateHorizBox(GadCon);
EB_AddLastSon(root, b3);
EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
root = EB_CreateMasterWindow(GadCon, Win, root);
if (EB_ProcessGadBoxes(GadCon, root))
{
ret = 1;
}
}
return ret;
}
BYTE CreateWindow(void)
{
BYTE ret = 0;
if (CreateGfx())
{
GadCon->NewWin->Title = "EGS Gadget Demo 5";
GadCon->NewWin->Flags &= ~EI_SMART_REFRESH;
GadCon->NewWin->Flags |= (EI_SIZEBBOTTOM | EI_WINDOWCENTER);
GadCon->NewWin->IDCMPFlags |= (EI_iCLOSEWINDOW | EI_iGADGETUP | EI_iSIZEVERIFY | EI_iNEWSIZE);
GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE | EI_WINDOWSIZE);
if (Win = EI_OpenWindow(GadCon->NewWin))
{
ret = 1;
}
}
return ret;
}
main()
{
struct EI_EIntuiMsg *IMsg;
struct EI_Gadget *TempGad;
BYTE quit = 0;
if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
{
if (EGBBase = OpenLibrary("egsgadbox.library", 0))
{
if (CreateWindow())
{
while (!quit)
{
WaitPort(Win->UserPort);
if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
{
if (IMsg->Class == EI_iCLOSEWINDOW)
{
quit = 1;
}
if (IMsg->Class == EI_iGADGETUP)
{
TempGad = (struct EI_Gadget *)IMsg->IAddress;
if (TempGad->GadgetID == GAD_1_ID)
{
printf("You pressed me!\n");
}
if (TempGad->GadgetID == GAD_2_ID)
{
printf("You're not leaving me alone!\n");
}
if (TempGad->GadgetID == GAD_3_ID)
{
printf("You helped me!\n");
}
}
if (IMsg->Class == EI_iSIZEVERIFY)
{
EI_RemoveGList(Win, GadCon->First, GadCon->Num);
EB_DeleteGadContext(GadCon);
GadCon = NULL;
}
if (IMsg->Class == EI_iNEWSIZE)
{
EI_LockIntuition();
CreateGfx();
if (GadCon)
{
EI_AddGList(Win, GadCon->First, GadCon->Num);
}
EI_UnlockIntuition();
}
ReplyMsg((struct Message *)IMsg);
}
}
}
if (Win) EI_CloseWindow(Win);
if (GadCon) EB_DeleteGadContext(GadCon);
CloseLibrary(EGBBase);
}
CloseLibrary(EGSIntuiBase);
}
}